package com.go.where.family.api.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.go.where.family.api.server.HttpServerStartMain;
import com.go.where.family.api.vo.SmsVo;

/**
 * 
 * 短信工具类
 * 
 * @author java
 * 
 */
public class SMSUtil {

	private static Logger log = Logger.getLogger(SMSUtil.class);
	private static String cdKey = HttpServerStartMain.getValue("emay.cd.key");
	private static String password = HttpServerStartMain
			.getValue("emay.cd.password");

	/**
	 * 短信用户序列号注册
	 * 
	 * @return
	 */
	public static SmsVo regist() {
		SmsVo sms = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("cdkey", cdKey);
		map.put("password", password);
		String address = HttpServerStartMain.getValue("emay.regist.address");
		HttpClient hc = new HttpClient();
		try {
			log.info("发送到亿美注册用户序列号地址及参数：" + address + map);
			String result = hc.doPost(address, map);
			log.info("亿美注册用户序列号返回结果为：" + result);
			if (StringUtils.isNotBlank(result)) {
//				sms = ParseEmayInfo.parse(result);
			}

		} catch (Exception e) {
			log.error("亿美注册用户序列号异常", e);
		}

		return sms;

	}

	/**
	 * 发送短信
	 * 
	 * @return
	 */
	public static SmsVo sendMsm(String phone, String message) {
		SmsVo sms = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("cdkey", cdKey);
		map.put("password", password);
		map.put("phone", phone);
		map.put("message", message);
		map.put("smspriority", "5");
		String address = HttpServerStartMain.getValue("emay.sendmsm.address");
		HttpClient hc = new HttpClient();
		try {
			log.info("发送到亿美发送短信地址及参数：" + address + map);
			String result = hc.doPost(address, map);
			log.info("亿美发送短信返回结果为：" + result);
			if (StringUtils.isNotBlank(result)) {
//				sms = ParseEmayInfo.parse(result);
			}

		} catch (Exception e) {
			log.error("亿美发送短信异常", e);
		}

		return sms;

	}
}
